package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderAdminService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/order")
public class OrderAdminController {
    @Autowired
    OrderAdminService orderAdminService;

    /**
     * 拒单
     * @param ordersCancelDTO
     * @return
     */
    @PutMapping("/rejection")
    public Result refuseOrder(@RequestBody OrdersCancelDTO ordersCancelDTO){
        orderAdminService.refuseOrder(ordersCancelDTO);
        return Result.success();
    }

    /**
     * 派送订单
     *
     * @param id
     * @return
     */
    @ApiOperation("派送订单")
    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable(name = "id") Long id) {
        orderAdminService.giveOrder(id);
        return Result.success("开始派送");
    }

    /**
     * 订单搜索
     *
     * @param ordersPageQueryDTO
     * @return
     */

    @GetMapping("/conditionSearch")
    public Result conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {
        PageResult pageResult = orderAdminService.conditionSearch(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 取消订单
     *
     * @param ordersCancelDTO
     * @return
     */
    @PutMapping("/cancel")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO) throws Exception {
        orderAdminService.cancel(ordersCancelDTO);
        return Result.success();
    }

    /**
     * 完成订单
     *
     * @param
     * @param id
     * @return
     */
    @ApiOperation("完成订单")
    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable Long id) {
        orderAdminService.complete(id);
        return Result.success("已完成订单");
    }

    /**
     * 接单
     *
     * @param ordersConfirmDTO
     * @return
     */
    @PutMapping("/confirm")
    public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO) {
        orderAdminService.update(ordersConfirmDTO);
        return Result.success();
    }

    /**
     * 查询每个订单下的数量
     *
     * @return
     */
    @GetMapping("/statistics")
    public Result statistics() {
        OrderStatisticsVO orderStatisticsVO = orderAdminService.statistics();
        return Result.success(orderStatisticsVO);
    }

    /**
     * 查询订单详情
     *
     * @param id
     * @return
     */
    @GetMapping("/details/{id}")
    public Result details(@PathVariable Long id) {
        OrderVO details = orderAdminService.details(id);
        return Result.success(details);
    }

}